﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.TM
{
    public partial class SM_SelectEmployee : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            Response.Cache.SetNoStore();
            if (!IsPostBack)
            {
                DataTable dt = ZLDC.DAL.t_s_tmp_allusr.GetStation("");
                DDStation.DataSource = dt;
                DDStation.DataTextField = "station";
                DDStation.DataValueField = "station";
                DDStation.DataBind();

                DDStation.Items.Insert(0,new ListItem("== 请选择 ==",""));
                DataBindGv();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected void DataBindGv()
        {
            string strWhere = string.Empty;
            strWhere = " 1=1 ";
            if (Autocomplete5.Text!= null)
                strWhere += " and name like '%" + Autocomplete5.Text.Trim() + "%'";
            if (txtEmployeeNo.Value.Trim() != string.Empty)
                strWhere += " and no like '%" + txtEmployeeNo.Value.Trim() + "%'";
            ///strWhere += " and id not in (select EmpID from zldc.t_s_Role_Employee where RoleID=" + Request["RoleID"].Trim() + ")";
            if (Autocomplete1.SelectValue!=null && Convert.ToInt32(Autocomplete1.SelectValue) > 0)
                strWhere+=" and t_id='"+Autocomplete1.SelectValue+"'";
            if (DDStation.SelectedItem.Value != "")
                strWhere += " and Station='" + DDStation.SelectedItem.Text + "'";

            string strRoleID = ZLDC.BLL.t_s_tmp_allusr.GetStrEmpIDs(Request["RoleID"].Trim());
            if (strRoleID != string.Empty)
                strWhere += " and id not in (" + strRoleID + ")";
            int recount = 0;
            dlistData.DataSource = ZLDC.BLL.t_s_tmp_allusr.GetListAllUsr(strWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out recount);
            dlistData.DataBind();
            AspNetPager1.RecordCount = recount;
            ZLDC.Common.CmnFunc.setCustInfoOfAspnet(AspNetPager1);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            DataBindGv();
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            DataBindGv();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strValue = txtIDS.Value.Substring(0, txtIDS.Value.Trim().Length - 1);
            for (int i = 0; i < strValue.Split(',').Length; i++)
            {
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.InsertT_s_Role_Employee(Request["RoleID"].Trim(), strValue.Split(',')[i]);
            }

            Response.Write("<script>alert('添加成功！');window.returnValue='1';window.close();</script>");
        }
    }
}
